package baidu.comparator;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class TestComparableAndrater implements Comparable<TestComparableAndrater>{

	private String name = "";
	
	public TestComparableAndrater(String name){
		this.name = name;
	}
	
	
	
	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	@Override
	public String toString() {
		return name;
	}

	private double order;
	
	
	
	public double getOrder() {
		return order;
	}

	public void setOrder(double order) {
		this.order = order;
	}
	
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TestComparableAndrater t1 = new TestComparableAndrater("t1");
		t1.setOrder(2);
		TestComparableAndrater t2 = new TestComparableAndrater("t2");
		t2.setOrder(1);
		TestComparableAndrater[] arrs = {t1, t2};
		Arrays.sort(arrs, new Comparator<TestComparableAndrater>() {

			public int compare(TestComparableAndrater o1,
					TestComparableAndrater o2) {
				return o1.getName().compareTo(o2.getName());
			}
		});
		System.out.println(Arrays.toString(arrs));
		
		
	}

	public int compareTo(TestComparableAndrater another) {
		double thisOrder = this.getOrder();
		double anotherOrder = another.getOrder();
		return thisOrder<anotherOrder ? -1 : (thisOrder==anotherOrder ? 0 : 1);
	}
	

}
